﻿using System.ComponentModel;
using System.Linq;

namespace Marmat.Forms
{
    public partial class BindingField
    {
        public class StringConverter : System.ComponentModel.StringConverter
        {
            public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
            {
                return true;
            }

            public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                string[] dataMembers = null;
                BindingField BindingField = (BindingField)context.Instance;
                if (BindingField.DataSource is object)
                {
                    dataMembers = BindingField.DataSource.GetColumnCollection().Select(x => x.Name).ToArray();
                }

                return new StandardValuesCollection(dataMembers);
            }

            public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
            {
                return false;
            }
        }
    }
}